/*
 * CalendarsTableModel.java
 *
 * Created on 7 de Dezembro de 2006, 23:13
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package mypodsync.service.calendar;

import java.util.ArrayList;
import java.util.List;

import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Andre Andrade Costa
 */
public class CalendarsTableModel extends AbstractTableModel {

    private List<String> keys;
    private List<String> vals;
    
    /** Creates a new instance of CalendarsTableModel */
    public CalendarsTableModel() {
        keys = new ArrayList<String>();
        vals = new ArrayList<String>();
    }

    public int getRowCount() {
        return keys.size();
    }

    public int getColumnCount() {
        return 2;
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        if (columnIndex == 0) {
            return keys.get(rowIndex);
        } else {
            return vals.get(rowIndex);
        }
    }
    
    @Override
    public String getColumnName(int column) {
        if (column == 0) {
            return "Name";
        } else {
            return "URL";
        }
    }
    
    public void add(String name, String url) {
        keys.add(name);
        vals.add(url);
        fireTableDataChanged();
    }
    
    public void remove(int sel) {
        keys.remove(sel);
        vals.remove(sel);
        fireTableDataChanged();
    }

    public void clear() {
        keys.clear();
        vals.clear();
    }
}
